package flexo.examples;

import flexo.graphic.Material;
import flexo.graphic.ShaderParam;
import flexo.math.*;
import flexo.scene.Node;

public class Test_Graphic_Outline extends Test_Graphic_Base
{
	flexo.math.Quaternion rotation;
	flexo.math.Vector elapPos;
	flexo.scene.Node root;
	
	public static void main(String[] args)
	{
		run("flexo.examples.Test_Graphic_Outline");
	}
	
	public void init()
	{
		super.init();
		root = mainScene.addChild("root");
		
		rotation = Quaternion.createRotationY(0.1f);
		elapPos = new Vector(0,0.00001f,0);
		
		flexo.graphic.Material mat = graphic.addMaterial("default", "default");
		flexo.graphic.ShaderParam pTex = mat.getShaderParam("tex");
		pTex.setValue("textures/stone.jpg");

		flexo.graphic.entity.Entity obj = graphic.addMesh("models/knot.obj");		
		obj.setMaterial("default");
		obj.attachTo(root);
		flexo.graphic.entity.Entity cel = graphic.addMesh("models/knot.obj");
		Material outline = graphic.addMaterial("outline", "outline");
		outline.setReversePolygons(true);
		ShaderParam scale = outline.getShaderParam("scale");
		scale.setValue(0.03f);
		cel.setMaterial("outline");
		cel.attachTo(root);
		root.setPosition(new Vector(0,0,0));
		root.setScale(5);
		
		Node shadow = root.addChild("shadow");
		shadow.setPosition(new Vector(0,-0.2f,0));
		shadow.setScale(new Vector(1,0,1));
		cel.attachTo(shadow);
	}

	public void cleanUp()
	{
	}	

	public void update()
	{
		rotation.fromAxis(new flexo.math.Vector(0,1,0), getElapsedTime() * 20);
		root.rotate(rotation);
	}
}
